﻿/// <reference path="DocumentResource.ts" />
/// <reference path="ResourceManager.ts" />

module HeadTS {

    export interface Predicate {
        (): Boolean
    }

    export class Loader {

        private manager: ResourceManager;

        constructor(public doc: HTMLDocument) {

            this.manager = new ResourceManager(doc);
        }

        loadAsync(resources: DocumentResource[]): Promises.IPromise {

            // Load each resource using the manager.
            var pendingResources = [];
            for (var i = 0; i < resources.length; i++) {
                pendingResources.push(this.manager.loadAsync(resources[i]));
            }

            // Return a Promise to represent when all the resources have been loaded.
            return Promises.Promise.whenAll(pendingResources);
        }
    }

}